package com.example.filter;

import com.example.http.MyHttpServletRequestWrapper;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @program: sms
 * @description:
 * @author: zhanghz001
 * @create: 2020-11-04 13:41
 **/
@WebFilter("/DemoServlet01")
public class HttpFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException,
            ServletException {
        System.out.println("HttpFilter 过滤器");
        HttpServletResponse response = (HttpServletResponse) resp;
        HttpServletRequest request = (HttpServletRequest) req;
        //装饰器模式
        MyHttpServletRequestWrapper wrapper = new MyHttpServletRequestWrapper(request);
        chain.doFilter(wrapper, response);
    }

    @Override
    public void destroy() {

    }
}
